﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EasyPiano
{
    public partial class MusicScoreControl : UserControl
    {
        private string soundStr1 = "1";
        private string soundStr2 = "2";
        private string word = "";
        private bool isTwoScore;
        private bool hasWord;
        int delay = 1;

        public string SoundStr2
        {
            get => soundStr2;
            set
            {
                soundStr2 = value;
                lb2.NumberText = value;
            }
        }
        public string SoundStr1
        {
            get => soundStr1;
            set
            {
                soundStr1 = value;
                lb1.NumberText = value;
            }
        }
        public bool IsTwoScore
        {
            get => isTwoScore;
            set
            {
                isTwoScore = value;
                if (isTwoScore == false)
                {
                    SoundStr2 = "0";
                }
                SetHeightAndPosition();
            }
        }
        public int Delay
        {
            get => delay;
            set
            {
                delay = value;
                if (delay < 1)
                    delay = 1;
                this.Width = delay * 25;
            }
        }

        public bool HasWord
        {   get => hasWord;
            set
            {
                this.hasWord = value;
                if(this.hasWord==false)
                {
                    this.lb_word.Text = "";
                }
                SetHeightAndPosition();
            }
        }

        public string Word
        {
            get => word;
            set
            {
                word = value;
                lb_word.Text = word;
            }
        }

        void SetHeightAndPosition()
        {
            int c = 0;
            if (isTwoScore)
            {
                c++;
                lb2.Height = 50;                
            }                
            else
            {
                lb2.Height = 0;
            }

            if (hasWord)
            {
                c++;
                lb_word.Height = 50;
                if(isTwoScore)
                {
                    lb_word.Location = new Point(0, 100);
                }
                else
                {
                    lb_word.Location = new Point(0, 50);
                }
            }
            else
            {
                lb_word.Height = 0;
            }                
            this.Height = (c + 1) * 50;
        }

        public void Selected()
        {
            this.BackColor = Color.Orange;
        }
        public void Playing()
        {
            this.BackColor = Color.Green;
        }
        public void CancelSelect()
        {
            this.BackColor = Color.Transparent;
        }

        public MusicScoreControl()
        {            
            InitializeComponent();
            IsTwoScore = false;
            Delay = 1;
            SoundStr1 = "0";
            SoundStr2 = "0";
        }

        private void lb_Click(object sender, EventArgs e)
        {
            base.OnClick(e);
        }
    }
}
